package com.example.demo.controller;

import com.example.demo.bo.User;
import com.example.demo.dto.LoginFormDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <h3>wechat-token</h3>
 * <p></p>
 *
 * @author : zhengyue
 * @date : 2021-05-19 12:55
 **/
@RestController
@RequestMapping("user")
public class UserController {
    Map<String, Object> map = new HashMap<>();

    /**
     * @Description: openid校验
     * @Author: zhengyue
     * @Date: 2021/5/19 12:55
     * @Param: []
     * @Return: java.lang.Boolean
     */
    @GetMapping("validOpenid")
    public Boolean validOpenid(String openid) {
        Object user = map.get(openid);
        if(ObjectUtils.isEmpty(user)) {
            return false;
        }
        return true;
    }

    @PostMapping("login")
    public Boolean login(@RequestBody LoginFormDTO dto) {
        // 模拟入库
        User user = new User();
        BeanUtils.copyProperties(dto, user);
        map.put(dto.getOpenid(), user);
        return true;
    }
}
